//==============================================================================
// GenBankEntry.hh
// ----------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
// $Id: $
//------------------------------------------------------------------------------
//
//==============================================================================
//.......1.........2.........3.........4.........5.........6.........7.........8
//

#include "LocalSTL.hh"
#include "Sequence.hh"
#include "ParseUtils.hh"

#ifndef _GENBANK_ENTRY
#define _GENBANK_ENTRY

// Note: Order IS important.  "join" must be at the start.
// "END" is not a keyword but indicates end of gFeatureNames
static string 
		gFeatureNames[]=
		{"join","exon","intron","gene","mRNA","CDS","5'UTR","3'UTR","END"};


//------------------------------------------------------------------------------
// * Feature
//------------------------------------------------------------------------------
//
// A single feature in the genbank record.  This can be any of:
//
// join, exon, intron, gene, mRNA, CDS, 5'UTR, 3'UTR, or END.  
//
//
class Feature{
public:
	string			mKind;
	string			mName;
	
	int				mJoinID;
	int				mStart;
	int				mEnd;
	
	void	Print(ostream &out){out<<mKind<<"\t"<<mStart<<".."<<mEnd<<"\t("<<mJoinID<<")";};
};

//------------------------------------------------------------------------------
// * CDS
//------------------------------------------------------------------------------
// Coding sequence.  Includes amino acid translation. 
// 
class CDS : public Feature{
public:
	Sequence mTranslation;
};

//------------------------------------------------------------------------------
// * FeatureVec
//------------------------------------------------------------------------------
//
// A vector of GenBank record features. 
// 
class FeatureVec : public vector<Feature>{
public:
	void Print(ostream &out);
	
	// KJD use stable_sort to implement sort by 
	// mKind, mJoinID, mStart, or mEnd
	// void StableSortByKind();
	// void StableSortByJoin();
	// void StableSortByStart();
	// void StableSortByEnd();
};

//------------------------------------------------------------------------------
// * GenBankEntry
//------------------------------------------------------------------------------
//
// Represents a single GenBankEntry.  Includes methods to parse the GenBank 
// text file into a feature vector.  Very handy.  
//
class GenBankEntry{
public:
	GenBankEntry(){InitKeywordList(); mJoinIdx = 1;};
	~GenBankEntry(){};
	
	vector<string> mKeywordList;
	
	int			mJoinIdx; // Joins are associated via an index number
	
	string		mName;
	string 		mAccession;
	FeatureVec	mFeatures;
	Sequence	mSequence;
	
	void InitKeywordList();
	void ParseFeatureLine(string &Line,int offset);
	void ParseFASTALine(string &Line);
	bool ParseGenBankFile(const string &FileName);
	
};

#endif
